package com.ycb.common;

import com.ycb.exception.CustomException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author ycb 全局异常处理
 * @Version 1.0
 * @Date 2024/10/4 15:14
 */
@ControllerAdvice(annotations = {RestController.class, Controller.class})
@RestController//将返回结果包装成json数据
@Slf4j
public class GlobalExceptionHandler {
    // @ExceptionHandler//异常捕获注解
    public Result<String> exceptionHandle(Exception e) {
        log.info(e.getMessage());
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(value = CustomException.class)
    public Result<String> exceptionCustomHandle(CustomException e) {
        log.error(e.getMessage());
        return Result.error(e.getMessage());
    }
}
